using UnityEngine;
using System.Collections;

[System.Serializable]

public class BoostInfo
{
	
	public Texture2D[] boostAnimationImgs;
	public float xVel;
	public float yVel;
	private float currentVelX;
	private float currentVelY;
	private float boostCronometer;
	public float boostLifeTime;
	public float boostVel;
	private GameObject playerGo;
	private PlayerMechanic playerMechanic;
	private bool boostInvincibility = false;
	
	public bool getBoostInvincibility ()
	{
		return this.boostInvincibility;
	}
	
	public void Awake ()
	{
		this.playerGo = GameObject.FindGameObjectWithTag (Tags.PLAYER);
		this.playerMechanic = playerGo.GetComponent<PlayerMechanic> ();
	}
	
	public void Start ()
	{
		
	}
	
	public void Update ()
	{
		if (this.boostCronometer < this.boostLifeTime) {
		
			if (!this.boostInvincibility) {
				this.boostInvincibility = true;
			}	
				
			this.currentVelX = Input.GetAxis ("Horizontal") * boostVel;
			this.currentVelY = Input.GetAxis ("Vertical") * this.yVel;
				
			this.currentVelX *= Time.deltaTime;
			this.currentVelY *= Time.deltaTime;
				
			this.playerGo.transform.Translate(new Vector3(this.currentVelX, this.currentVelY, 0));
			
			Vector3 tmpPosition = new Vector3(playerGo.transform.position.x, playerGo.transform.position.y, playerGo.transform.position.z);
			
			if(this.playerGo.transform.position.y > playerMechanic.maxAltitude){
				tmpPosition.y = playerMechanic.maxAltitude;
			}
			
			if(this.playerGo.transform.position.y < playerMechanic.minAltitude){
				tmpPosition.y = playerMechanic.minAltitude;
			}
			
			if(this.playerGo.transform.position.x > playerMechanic.maxLongitude)
			{
				tmpPosition.x = playerMechanic.maxLongitude;
			}
			
			if(this.playerGo.transform.position.x < playerMechanic.minLongitude)
			{
				tmpPosition.x = playerMechanic.minLongitude;
			}
			
			this.playerGo.transform.position = tmpPosition;

			this.boostCronometer += Time.deltaTime;
		
				
		} else {
			this.boostCronometer = 0;
			this.boostInvincibility = false;
			this.playerMechanic.ChangeMode (PlayerState.Normal);
			PlayerMechanic.gameVel = 1;
			Debug.Log (" ----- Terminou Boost  Mode ----- ");
				
		}
	}
	
}
